package com.xy.mainp.config;

import android.text.TextUtils;

import java.io.IOException;

/**
 * Created by John on 2016/11/3.
 */

public class NetAPI {
    public static final String IP_URL = "http://pv.sohu.com/cityjson";

    public static final String BASE_URL = "http://gank.io/api/data";

    public static final String HUABAN_SEARCH_BASE_URL = "http://huaban.com/search/?";
    public static final String HUABAN_BASE_URL = "http://huaban.com";

    public static final String BIQU_BASE_URL = "http://www.biquge.tw";

    public static String getHomeDataUrl(String... ps) {
        int length = ps.length;
        StringBuilder str = new StringBuilder(BASE_URL);
        for (int i = 0; i < length; i++) {
            str.append("/" + ps[i]);
        }
        return str.toString();
    }

    public static String getHuabanDataUrl(String qAndcategory) {
        return HUABAN_BASE_URL + qAndcategory;
    }

    public static String getBiQuDataUrl(String qAndcategory){
        return BIQU_BASE_URL + qAndcategory;
    }

    public static String getHuabanDataUrl(String q, String category, String page, String prePage, String wlf) throws IOException {
        StringBuilder str = new StringBuilder(HUABAN_SEARCH_BASE_URL);
        if (!TextUtils.isEmpty(q)) {
            str.append("q=" + q);
        } else {
            throw new IOException("关键字不能为空");
        }
        if (!TextUtils.isEmpty(category)) {
            str.append("&category=" + category);
        }
        if (!TextUtils.isEmpty(page)) {
            str.append("&page=" + page);
        }
        if (!TextUtils.isEmpty(prePage)) {
            str.append("&prePage=" + prePage);
        }
        if (!TextUtils.isEmpty(wlf)) {
            str.append("&wlf=" + wlf);
        }


        return str.toString();
    }


}
